package com.yangjun.controller.report;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yangjun.service.report.OrderTransactionReprotExportService;
import com.yangjun.vo.report.OrderTransactionReportExportVO;

@RestController
@RequestMapping(value="/excel/order")
public class OrderTransactionReportController {
	
	@Autowired
	private OrderTransactionReprotExportService orderTransactionReprotExportService;

	@ResponseBody
	@RequestMapping("/getDeminsion")
	public Object getDeminsion(@RequestParam(value="reportid")String reportid,@RequestParam(value="userid")String userid){
		return orderTransactionReprotExportService.getDeminsion(reportid,userid);
	}
	@ResponseBody
	@RequestMapping("/getOrderstatus")
	public Object getOrderstatus(@RequestParam(value="caliberType")String caliberType,@RequestParam(value="outstockType") String[] outstockType,@RequestParam(value="orderstatus") String[] orderstatus){
		return orderTransactionReprotExportService.queryOrderstatus(caliberType,outstockType,orderstatus);
		
	}
	@ResponseBody
	@RequestMapping("/getSearchTemplate")
	public Object getSearchTemplate(@RequestParam(value="analysisType")String analysisType,@RequestParam(value="caliberType")String caliberType,@RequestParam(value="searchName")String searchName){
		return orderTransactionReprotExportService.querySearch(analysisType,caliberType,searchName);
	}
	@ResponseBody
	@RequestMapping("/getTarget")
	public Object getTarget(@RequestParam(value="userid")String userid,@RequestParam(value="caliberType")String caliberType,@RequestParam(value="selectTarget")String[] targetSelectData){
		return orderTransactionReprotExportService.queryTarget(userid,caliberType,targetSelectData);
	}	
	
	
	@ResponseBody
	@RequestMapping("/queryData")
	public Object queryData(OrderTransactionReportExportVO otreVo){
		System.out.println("查询数据接口："+otreVo);
//		//	orderMain("订单主表","orderMain"),orderDetail("订单明细","orderDetail");
//		otreVo.setAnalysisType("orderDetail");
//		otreVo.setBeginDate("2017-10-27");
//		otreVo.setEndDate("2017-10-28");
//		//	ordered("下单","ordered"),outstock("出库","outstock"),returned("退货","return");
//		otreVo.setCaliberType("return");
//		//	self_outstock("自主出库",0),third_outstock("厂家代发",1);
//		String[] outstock = new String[]{"自主出库","厂家代发"};
//		otreVo.setOutstockType(outstock);
//		
//		String[] payType = new String[]{"在线支付","银行电汇","货到付款","邮局汇款","现金自提","账户支付"};
//		otreVo.setPayType(payType);
//		
//		String[] orderstatus = new String[]{"未付款","Rx已复核","已付款","已审核","Rx未复核","部分生成","完全生成","完全出库","已取消","已完成","已删除"};
//		otreVo.setOrderstatus(orderstatus);
//		
//		String[] ordersource = new String[]{"1","4","14","101"}; 
//		otreVo.setOrdersource(ordersource);
//		//下单
//		String[] target = new String[]{"sourcename","shopname","channelname","ordercode","originorderid","changetype","orderstatus","stockstatus","sumamt","orderfreightcost","appendfreightcost","prmcode","prmname","disamt","orderpointsamt","netamt","unpaidamt","payconcode","paystatus","cuscode","cusname","ordernumber","isNewMember","creatorcode","creator","createdate","dataDate","orgname","consigncode","consignweight","deliverynumber","deliverycompany","province","city","district"};
//		//退货
//		String[] target = new String[]{"model","manufacturername","facategory","department","isrx","isthirdgoods","waremanagerpc","inprice","purchasecost","grossprofit","fagrossprofit","stockcount","returnprice","returnamount","fareturnprice","fareturnamount","sourcename","shopname","channelname","ordercode","originorderid","sourcename","shopname","payconcode","cuscode","cusname","ordernumber","isNewMember","creatorcode","creator","returnid","orderReturnamount","orderFareturnamount","refunddetailcause","remark","returntype","stocktime","createdate"};
//		otreVo.setTarget(target);
		return orderTransactionReprotExportService.queryData(otreVo);
	}
	@ResponseBody
	@RequestMapping("/queryDataByReportId")
	public Object queryDataByReportid(@RequestParam(value="reportid")String reportid){
		System.out.println("根据ID查询数据接口："+reportid);
		return orderTransactionReprotExportService.queryData(reportid);
	}
	@ResponseBody
	@RequestMapping("/addReport")
	public Object addReport(OrderTransactionReportExportVO otreVo){
		System.out.println("加入报表："+otreVo);
		return orderTransactionReprotExportService.addOrUpdateReport(otreVo);
	}
	@ResponseBody
	@RequestMapping("/addDownloadTaskByReportId")
	public Object addDownloadTaskByReportId(@RequestParam(value="reportid")String reportid,HttpServletRequest request){
		System.out.println("根据ID加入下载列表："+reportid);
		return orderTransactionReprotExportService.addDownloadTask(reportid,request);
	}	
	
	@ResponseBody
	@RequestMapping("/addDownloadTask")
	public Object addDownloadTask(OrderTransactionReportExportVO otreVo,HttpServletRequest request){
		System.out.println("加入下载列表："+otreVo);
//		orderMain("订单主表","orderMain"),orderDetail("订单明细","orderDetail");
//			otreVo.setAnalysisType("orderDetail");
//			otreVo.setBeginDate("2017-10-27");
//			otreVo.setEndDate("2017-10-28");
//				//ordered("下单","ordered"),outstock("出库","outstock"),returned("退货","return");
//			otreVo.setCaliberType("return");
//			//	self_outstock("自主出库",0),third_outstock("厂家代发",1);
//			String[] outstock = new String[]{"自主出库","厂家代发"};
//			otreVo.setOutstockType(outstock);
//			
//			String[] payType = new String[]{"在线支付","银行电汇","货到付款","邮局汇款","现金自提","账户支付"};
//			otreVo.setPayType(payType);
//			
//			String[] orderstatus = new String[]{"未付款","Rx已复核","已付款","已审核","Rx未复核","部分生成","完全生成","完全出库","已取消","已完成","已删除"};
//			otreVo.setOrderstatus(orderstatus);
//			
//			String[] ordersource = new String[]{"1","4","14","101"}; 
//			otreVo.setOrdersource(ordersource);
//			//下单
//			String[] target = new String[]{"sourcename","shopname","channelname","ordercode","originorderid","changetype","orderstatus","stockstatus","sumamt","orderfreightcost","appendfreightcost","prmcode","prmname","disamt","orderpointsamt","netamt","unpaidamt","payconcode","paystatus","cuscode","cusname","ordernumber","isNewMember","creatorcode","creator","createdate","dataDate","orgname","consigncode","consignweight","deliverynumber","deliverycompany","province","city","district"};
//			//退货
//			String[] target = new String[]{"model","manufacturername","facategory","department","isrx","isthirdgoods","waremanagerpc","inprice","purchasecost","grossprofit","fagrossprofit","stockcount","returnprice","returnamount","fareturnprice","fareturnamount","sourcename","shopname","channelname","ordercode","originorderid","sourcename","shopname","payconcode","cuscode","cusname","ordernumber","isNewMember","creatorcode","creator","returnid","orderReturnamount","orderFareturnamount","refunddetailcause","remark","returntype","stocktime","createdate"};
//			otreVo.setTarget(target);
		return orderTransactionReprotExportService.addDownloadTask(otreVo,request); 
	}
}
